package com.ecgsystem.activity;

import com.ecgsystem.activity.R;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

/**
 * TODO Put here a description of what this class does.
 *
 * @author ANHTUAN.
 *         Created Sep 28, 2012.
 */
public class PatientTab extends TabActivity {
	/** Called when the activity is first created. */
	private int clickedposition;
	/**
	 * TODO Put here a description of this field.
	 */
	public static Context tabActivityContex;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		tabActivityContex = this.getApplicationContext();
		
		setContentView(R.layout.patienttab);

		Bundle receiveBundle = this.getIntent().getExtras();
		this.clickedposition = receiveBundle.getInt("clickedposition");
		
		Bundle bPatientInfo = new Bundle();
		
		bPatientInfo.putInt("clickedposition", this.clickedposition);
		
		
		Intent iPatientInfo = new Intent(this, PatientInfo.class);
		Intent iOnlineEcg = new Intent(this, OnlineECG.class);
		//Intent iOfflineEcg = new Intent(this, StoredSignal.class);
		
		iPatientInfo.putExtras(bPatientInfo);
		iOnlineEcg.putExtras(iOnlineEcg);
		//iOfflineEcg.putExtras(iOfflineEcg);
		
		MainActivity.tabHost = (TabHost) findViewById(android.R.id.tabhost);

		TabSpec firstTabSpec = MainActivity.tabHost.newTabSpec("tid1");
		TabSpec secondTabSpec = MainActivity.tabHost.newTabSpec("tid2");
		//TabSpec thirdTabSpec = MainActivity.tabHost.newTabSpec("tid3");
		
		firstTabSpec.setIndicator("Patient's Info", getResources().getDrawable(R.drawable.pi)).setContent(iPatientInfo);
		secondTabSpec.setIndicator("Online ECG", getResources().getDrawable(R.drawable.ecg)).setContent(iOnlineEcg);
		//thirdTabSpec.setIndicator("Stored ECG", getResources().getDrawable(R.drawable.ecg)).setContent(iOfflineEcg);

		MainActivity.tabHost.addTab(firstTabSpec);
		MainActivity.tabHost.addTab(secondTabSpec);
		//MainActivity.tabHost.addTab(thirdTabSpec);
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode == KeyEvent.KEYCODE_BACK){
			Bundle patientList = new Bundle();

			Intent i = new Intent(PatientTab.this,
					PatientList.class);
			i.putExtras(patientList);
			startActivity(i);
			finish();
		}
		return true;
	}
}